﻿using OABLL;
using OAModel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyOA
{
    public partial class Login :Form
    {
        public  string oa;
        
        public Login()
        {
            InitializeComponent();
        }
        //登录账号
        private void btnLogin_Click(object sender, EventArgs e)
        {
           
            string uid=this.txt员工id.Text.Trim();
            string pwd=this.txt密码.Text.Trim();
           
            if(uid != "" && uid.Length > 0)
            {
                if (pwd.Length >= 3 && pwd.Length <= 16)
                {
                    try
                    {
                        OAUseBLL bll = new OAUseBLL();
                        if (bll.IsUser(uid, pwd))
                        {
                            oa = uid;
                            OAUseEntity user = new OAUseEntity();
                            if(bll.zh(uid, user)) {
                            this.Hide();
                            new Main(oa).Show();
                            }
                            else
                            {
                                MessageBox.Show("该账号已被禁用");
                            }
                        }
                        else
                        {
                            MessageBox.Show("账号或密码错误", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("数据库连接失败" + ex.ToString());
                    }
                }
                else
                {
                    MessageBox.Show("密码长度错误，请输入正确密码！6-15位之间", "密码错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                } else{
                        MessageBox.Show("账号不能为空！", "账号错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
            }

        //员工信息注册跳转界面
        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            new YGzhuce().ShowDialog();
        }

      
    }
}
